void Analysis()
{  
 while (Serial1.available()>0)
  {
    uint8_t a = Serial1.read();
    if(err){
      if(err_p != 0 && a==0xaa)
        err_p = 0;
      else if(err_p == 0 && a==0xaa)
        err_p = 1;
      else if(err_p == 1 && a==0xf2) {
        err = false;
        check_sum = 0xaa+0xaa;
        function = 0xf2;
        current_length = 2;
      }
      else {
        err_p = 2;
        continue;
      }
    }

    if(current_length < length+4)
      check_sum += a;
    if(current_length > 3 && current_length < length+4) {
      c2i.c[current_length-4+(current_length%2 ? -1:1)] = a;//swap 2-bytes data endian
      current_length++;
      continue;
    }

    switch(current_length) {
      case 0:
        check_sum = 0xaa;
      case 1:
        if(a != 0xaa)
          err = true; 
        break;
      case 2:
        function = a;
        break;
      case 3:
        length = a;
        break;
      default:
        if(current_length == length+4 && a != check_sum) {
          err = true;
          Serial.println(a,HEX);
          Serial.println(check_sum,HEX);
        }
    }
    //
    if(!err && function == 0xf2 && current_length == length+4) {
      fix_speed_x=(c2i.i[0]);
      fix_speed_y=(c2i.i[1]);
      fix_dot_x=(c2i.i[2]);
      fix_dot_y=(c2i.i[3]);
      fix_dot_z=(c2i.i[4]);
      dist_out=(c2i.i[5]);
    }
    if(current_length != length+4)
      current_length++;
    else
      current_length = 0;
  }
  dataServer_parse_query(Serial);
}
